package com.hluck.mvvmlibrary;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author： LJH
 * @Time： 2023/12/22
 * @description：
 */
public class ActivityManager {

    private final List<Activity> activityList = new ArrayList<Activity>();

    /**
     * 添加Activity到管理器
     * @param activity
     */
    public void addActivity(Activity activity) {
        if (activity != null) {
            activityList.add(activity);
        }
    }

    /**
     * 从管理器移除Activity
     * @param activity
     */
    public void removeActivity(Activity activity) {
        if (activity != null) {
            activityList.remove(activity);
        }
    }

    /**
     * 关闭所有Activity
     */
    public void finishAll(){
        for (Activity activity : activityList) {
            activity.finish();
        }
    }

    public Activity getTaskTop(){
        return activityList.get(activityList.size() - 1);
    }
}
